package cn.jhc.db;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.h2.jdbcx.JdbcDataSource;

public class MyDbUtils {

	public static void createTables(JdbcDataSource dataSource) {
		QueryRunner runner = new QueryRunner(dataSource);

		String createSql = "create table if not exists user(id int auto_increment primary key,"
				+ "username varchar(255) unique,"
				+ "email varchar(255) not null,"
				+ " password varchar(255) not null,)"
				;
		
		String createSongSql = "create table if not exists song(songId int auto_increment primary key,"
				+"songname varchar(255) not null,"
				+ "songsinger varchar(255) not null,"
				+ "songimage varchar(255),"
				+ "songwords varchar(255),"
				+ "songURL varchar(255),)"
				;
		String createUserSongSql = "create table if not exists usersong(id int auto_increment primary key,"
				+ "username varchar(255) not null,"
				+ "songname varchar(255) not null,"
				+ "songsinger varchar(255) not null,)"
				;
		try {
			runner.update(createSql);
			runner.update(createSongSql);
			runner.update(createUserSongSql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}